home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DELPHI / CHOOZDCL.ZIP / CHOOZDCL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-30  |  5.2 KB  |  216 lines

  1. {$X+,D-,F+}
  2. program choozdcl;
  3.  
  4. {$R CHOOZ.RES}
  5.  
  6. uses
  7.   winTypes, winProcs, strings, oWindows;
  8.  
  9. const
  10.   appName: pChar = 'Delphi Launcher';
  11.  
  12. type
  13.   tDelphiLauncher = object(tApplication)
  14.     procedure initMainWindow; virtual;
  15.     destructor done; virtual;
  16.   end;
  17.  
  18.   pLaunchWindow = ^tLaunchWindow;
  19.   tLaunchWindow = object(tWindow)
  20.     constructor init(aParent: pWindowsObject;
  21.      aName: pChar);
  22.     destructor done; virtual;
  23.     procedure WMCreate(var Msg: TMessage);
  24.      virtual wm_First + wm_create;
  25.     procedure WMActivate(var Msg: TMessage);
  26.      virtual wm_First + wm_Activate;
  27.     procedure WMCommand(var Msg: TMessage);
  28.      virtual wm_First + wm_Command;
  29.     procedure fatal(const msg: string);
  30.   private
  31.     firstActivation: boolean;
  32.   public
  33.     count: word;
  34.     popup: hMenu;
  35.   end;
  36.  
  37. var
  38.   iniName: array [0..80] of char;
  39.  
  40. constructor tLaunchWindow.init(aParent: pWindowsObject;
  41.  aName: pChar);
  42. begin
  43.   count := 0;
  44.   firstActivation := true;
  45.   tWindow.init(aParent, aName);
  46.  {create an invisible, popup window}
  47.   attr.style := ws_popup;
  48. end;
  49.  
  50. destructor tLaunchWindow.done;
  51. begin
  52.   tWindow.done;
  53. end;
  54.  
  55. destructor tDelphiLauncher.done;
  56. begin
  57.   mainWindow^.done;
  58. end;
  59.  
  60. procedure tLaunchWindow.fatal(const msg: string);
  61. var
  62.   errMsg: array [0..255] of char;
  63. begin
  64.   messageBox(hWindow, strPCopy(errMsg, msg), appName, mb_iconExclamation + mb_ok);
  65.   postQuitMessage(1);
  66. end;
  67.  
  68. procedure tLaunchWindow.WMCreate(var Msg: TMessage);
  69. begin
  70.   if paramStr(1) = ''
  71.   then
  72.     strCopy(iniName, 'CHOOZDCL.INI')
  73.   else
  74.     strPCopy(iniName, paramStr(1));
  75. end;
  76.  
  77. procedure doEvents;
  78. var
  79.   m: tMsg;
  80. begin
  81.   while peekMessage(m, 0, 0, 0, pm_remove)
  82.   do
  83.     if m.message = wm_quit
  84.     then begin
  85.       postQuitMessage(m.wParam);
  86.       exit;
  87.      end
  88.     else begin
  89.       translateMessage(m);
  90.       dispatchMessage(m);
  91.     end;
  92. end;
  93.  
  94. procedure tLaunchWindow.WMCommand(var Msg: TMessage);
  95. var
  96.   libSect: array [0..1024] of char;
  97.   frmSect, toSect, key: array [0..80] of char;
  98.   toIni, command: array [0..128] of char;
  99.   valu: array [0..255] of char;
  100.   nrStr: string[2];
  101.   frm, idx: word;
  102. begin
  103.   if (msg.wParam > 0) and (count >= msg.wParam)
  104.   then begin
  105.     toIni[0] := #0;
  106.     getPrivateProfileString(strCopy(frmSect, 'General'),
  107.      'IniFile', '', toIni, sizeOf(toIni), iniName);
  108.     if toIni[0] = #0
  109.     then
  110.       strCopy(toIni, 'DELPHI.INI');
  111.     toSect[0] := #0;
  112.     getPrivateProfileString(frmSect, 'IniSection',
  113.      '', toSect, sizeOf(toSect), iniName);
  114.     if toSect[0] = #0
  115.     then
  116.       strCopy(toSect, 'Library');
  117.     str(msg.wParam, nrStr);
  118.     fillChar(libSect, sizeOf(libSect), 1);
  119.     libSect[0] := #0;
  120.     getPrivateProfileString(strPCopy(frmSect, 'Config' + nrStr),
  121.      nil, '', libSect, sizeOf(libSect), iniName);
  122.     if libSect[0] = #0
  123.     then
  124.       fatal('Section [' + strPas(frmSect) + '] not found in '
  125.        + strPas(iniName))
  126.     else begin
  127.       frm := 0; idx := 0;
  128.       while (idx < high(libSect))
  129.        and ((libSect[idx] > #0)
  130.        or ((libSect[idx] = #0) and (libSect[succ(idx)] <> #0)))
  131.       do begin
  132.         inc(idx);
  133.         if libSect[idx] = #0
  134.         then begin
  135.           move(libSect[frm], key[0], idx - frm);
  136.           valu[0] := #0;
  137.           getPrivateProfileString(frmSect, key,
  138.            '', valu, sizeOf(valu), iniName);
  139.           writePrivateProfileString(toSect, key,
  140.            valu, toIni);
  141.           frm := succ(idx);
  142.         end;
  143.       end;
  144.     end;
  145.     destroyMenu(popup);
  146.     doEvents;
  147.     command[0] := #0;
  148.     getPrivateProfileString('General', 'CommandLine',
  149.      '', command, sizeOf(command), iniName);
  150.     if command[0] = #0
  151.     then
  152.       strCopy(command, 'DELPHI.EXE');
  153.     if winExec(command, sw_show) < 32
  154.     then
  155.       fatal('Error launching ' + strPas(command));
  156.   end;
  157. end;
  158.  
  159. procedure tLaunchWindow.WMActivate(var Msg: TMessage);
  160. const
  161.   tpm_centerAlign = $04;
  162. var
  163.   cfgName: array [0..255] of char;
  164.   cfgNr: array [0..8] of char;
  165.   nrStr: string[2];
  166.   curPos: tPoint;
  167. begin
  168.   if firstActivation
  169.   then begin
  170.     firstActivation := false;
  171.     repeat
  172.       str(succ(count), nrStr);
  173.       strPCopy(cfgNr, 'Config' + nrStr);
  174.       cfgName[0] := #0;
  175.       getPrivateProfileString('Configurations', cfgNr, #0,
  176.        cfgName, sizeOf(cfgName), iniName);
  177.       if cfgName[0] <> #0
  178.       then begin
  179.         inc(count);
  180.         if count = 1
  181.         then
  182.           popup := createPopupMenu;
  183.         if (popup = 0)
  184.          or not appendMenu(popup, mf_string, count, cfgName)
  185.         then
  186.           fatal('Error creating menu');
  187.       end;
  188.     until (count = 20) or (cfgName[0] = #0);
  189.     if count = 0
  190.     then
  191.       fatal('Config1 entry missing from [Configurations] section of '
  192.        + strPas(iniName));
  193.     getCursorPos(curPos);
  194.     if not trackPopupMenu(popup, tpm_centerAlign, curPos.x - 5,
  195.      curPos.y - 5, 0, hWindow, nil)
  196.     then begin
  197.       destroyMenu(popup);
  198.       fatal('Unable to display menu');
  199.     end;
  200.     postQuitMessage(0);
  201.   end;
  202. end;
  203.  
  204. procedure tDelphiLauncher.initMainWindow;
  205. begin
  206.   mainWindow := new(pLaunchWindow, init(nil, appName));
  207. end;
  208.  
  209. var
  210.   application: tDelphiLauncher;
  211.  
  212. begin
  213.   application.init(appName);
  214.   application.run;
  215.   application.done;
  216. end.